//
//  Language.m
//  ShoppingCompare
//
//  Created by Wenjie on 11-6-12.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Language.h"
#import "RootViewController.h"
#import "Search.h"

@implementation Language

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	// Navigation set --------------------------------------
	self.title = @"Select A Language";
	[self.navigationItem setHidesBackButton:YES];
	self.view.backgroundColor = [UIColor whiteColor];
	
	UITableView* tabLanguage = [[[UITableView alloc] initWithFrame:CGRectMake(50.0f, 50.0f, 220.0f, 200.0f) style:UITableViewStyleGrouped] autorelease];
	tabLanguage.backgroundColor = [UIColor clearColor];
	[self.view addSubview:tabLanguage];
	
	tabLanguage.delegate = self;
	tabLanguage.dataSource = self;
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

// --------------------------------------
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section 
{
	return 2;
}

- (UITableViewCell*) tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath {
	UITableViewCellStyle style = UITableViewCellStyleSubtitle;
	UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"BaseCell"];
	if (!cell) cell = [[[UITableViewCell alloc] initWithStyle:style reuseIdentifier:@"BaseCell"] autorelease];
		
	if (indexPath.row == 0) {
		cell.textLabel.text = @"China";
		if (inTaobao) cell.accessoryType = UITableViewCellAccessoryCheckmark;
	} else {
		cell.textLabel.text = @"Japan";
		if (!inTaobao) cell.accessoryType = UITableViewCellAccessoryCheckmark;
	}
	return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	NSIndexPath* path1 = [NSIndexPath indexPathForRow:0 inSection:0];
	NSIndexPath* path2 = [NSIndexPath indexPathForRow:1 inSection:0];
	UITableViewCell* cell1 = [tableView cellForRowAtIndexPath:path1];
	UITableViewCell* cell2 = [tableView cellForRowAtIndexPath:path2];

	if (indexPath.row == 0) {
		inTaobao = YES;
		cell1.accessoryType = UITableViewCellAccessoryCheckmark;
		cell2.accessoryType = UITableViewCellAccessoryNone;
	} else {
		inTaobao = NO;
		cell1.accessoryType = UITableViewCellAccessoryNone;
		cell2.accessoryType = UITableViewCellAccessoryCheckmark;
	}
	RootViewController* rvc = (RootViewController*) [[UIApplication sharedApplication] delegate];
	UINavigationController* navi = [rvc->search navigationController];
	[navi popViewControllerAnimated:YES];
}
@end
